package top.minuy.structure.queue;
/**
 * @author Minuy
 * @time 14:59
 * @date 2021/8/22
 */
public class Test {

    public static double testQueue(Queue<Integer> queue, int opCount){

        System.out.println("队列测试：");
        boolean check = true;
        long startTime = System.nanoTime();
        for (int i=0;i<opCount;i++){
            queue.enqueue(i);
        }
        for (int i=0;i<opCount;i++){
            Integer tag = queue.dequeue();
            if (tag!=i){
                check = false;
            }
        }
        long endTime = System.nanoTime();
        System.out.println("check = "+check+", time = "+(endTime-startTime)/1000000000.0+" s");
        return (endTime-startTime)/1000000000.0;
    }

    public static void main(String[] args) {

        System.out.println("优先队列测试：");
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        Integer[] a = {1,2,3,1,2,3,7,8};
        for (Integer i:a) {
            priorityQueue.enqueue(i);
        }

        for (int i = 0;i<4;i++){
            System.out.print(" -->"+priorityQueue.dequeue());
        }
        System.out.println();



        ArrayQueue<Integer> queue = new ArrayQueue<>();

        queue.enqueue(1);
        for (int i=0;i<17;i++){
            if (i%4 == 0){
                queue.dequeue();
            }else{
                queue.enqueue(i+1);
            }
            System.out.println(queue);
        }

        System.out.println("---------------LoopQueue------------------");

        LoopQueue<Integer> loopQueue = new LoopQueue<>();

        loopQueue.enqueue(1);
        for (int i=0;i<17;i++){
            if (i%4 == 0){
                loopQueue.dequeue();
            }else{
                loopQueue.enqueue(i+1);
            }
            System.out.println(loopQueue);
        }

        System.out.println("---------------LinkedListQueue------------------");

        LinkedListQueue<Integer> linkedListQueue = new LinkedListQueue<>();

        linkedListQueue.enqueue(1);
        for (int i=0;i<17;i++){
            if (i%4 == 0){
                linkedListQueue.dequeue();
            }else{
                linkedListQueue.enqueue(i+1);
            }
            System.out.println(linkedListQueue);
        }

        System.out.println("性能测试：");
        int opCount = 100000;
        System.out.println("Array Queue : ");
        testQueue(new ArrayQueue<Integer>(), opCount);

        System.out.println("Loop Queue : ");
        testQueue(new LoopQueue<Integer>(), opCount);

        System.out.println("Loop Queue 2: ");
        testQueue(new LoopQueueWork_2<>(), opCount);

        System.out.println("Loop Queue 1: ");
        testQueue(new LoopQueueWork_1<>(), opCount);

        System.out.println("Linked List Queue: ");
        testQueue(new LinkedListQueue<>(), opCount);
    }
}
